package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import com.greensock.*;

    public class BookmarksClear extends Sprite
    {
        var clearShell:BookmarksClearShell;
        var fadeSpeed:Number;
        public var coverSprite:Sprite;
        var myRoot:MovieClip;
        var longText:LongText;
        var myLink:BookmarkSaveLink;

        public function BookmarksClear(param1:MovieClip, param2:Number) : void
        {
            visible = false;
            alpha = 0;
            myRoot = param1;
            fadeSpeed = param2;
            buildLongTitle();
            clearShell = new BookmarksClearShell();
            clearShell.alpha = 1;
            addChild(clearShell);
            clearShell.submitBtn.buttonMode = true;
            clearShell.submitBtn.useHandCursor = true;
            clearShell.submitBtn.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
            clearShell.submitBtn.addEventListener(MouseEvent.ROLL_OVER, btnRollOver, false, 0, true);
            clearShell.submitBtn.addEventListener(MouseEvent.ROLL_OUT, btnRollOut, false, 0, true);
            buildCoverSprite();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            doResize();
            return;
        }

        function buildCoverSprite() : void
        {
            myLink = new BookmarkSaveLink();
            myLink.field1.field.text = myRoot.path + "www/#/bookmarks/browse/" + myRoot.myBookmarksID + "/";
            myLink.field1.field.addEventListener(FocusEvent.FOCUS_IN, focusInListener, false, 0, true);
            myLink.saveBtn.buttonMode = true;
            myLink.saveBtn.useHandCursor = true;
            myLink.saveBtn.addEventListener(MouseEvent.CLICK, saveBtnClick, false, 0, true);
            myLink.saveBtn.addEventListener(MouseEvent.ROLL_OVER, saveBtnRollOver, false, 0, true);
            myLink.saveBtn.addEventListener(MouseEvent.ROLL_OUT, saveBtnRollOut, false, 0, true);
            addChild(myLink);
            coverSprite = new Sprite();
            coverSprite.graphics.beginFill(16777215, 1);
            coverSprite.graphics.drawRect(0, 0, 1, 1);
            coverSprite.graphics.endFill();
            coverSprite.buttonMode = true;
            coverSprite.useHandCursor = false;
            coverSprite.alpha = 0;
            coverSprite.visible = false;
            addChild(coverSprite);
            return;
        }

        public function fadeOutShell() : void
        {
            visible = false;
            return;
        }

        function doResize() : void
        {
            if (coverSprite != null)
            {
                coverSprite.x = 0;
                coverSprite.y = Math.round(myRoot.headerH + 2 * (myRoot.unitH + myRoot.gutterH) - 5);
                coverSprite.width = 12 * (myRoot.unitW + myRoot.gutterW);
                coverSprite.height = 4 * (myRoot.unitH + myRoot.gutterH);
            }
            if (longText != null)
            {
                longText.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                longText.y = myRoot.headerH + (myRoot.unitH + myRoot.gutterH) - 4 * myRoot.unitW / 75;
                var _loc_1:* = myRoot.unitW / 75;
                longText.field.scaleY = myRoot.unitW / 75;
                longText.field.scaleX = _loc_1;
            }
            if (clearShell != null)
            {
                clearShell.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW) - 3 * myRoot.unitW / 75);
                clearShell.y = Math.round(myRoot.headerH + 2 * (myRoot.unitH + myRoot.gutterH));
                var _loc_1:* = myRoot.unitW / 75;
                clearShell.title1.scaleY = myRoot.unitW / 75;
                clearShell.title1.scaleX = _loc_1;
                var _loc_1:* = Math.round(211 * myRoot.unitW / 75);
                clearShell.submitBtn.width = Math.round(211 * myRoot.unitW / 75);
                clearShell.submitBG.width = _loc_1;
                var _loc_1:* = Math.round(26 * myRoot.unitW / 75);
                clearShell.submitBtn.height = Math.round(26 * myRoot.unitW / 75);
                clearShell.submitBG.height = _loc_1;
                var _loc_1:* = Math.round(59 * myRoot.unitW / 75);
                clearShell.submitBtn.y = Math.round(59 * myRoot.unitW / 75);
                clearShell.submitBG.y = _loc_1;
                var _loc_1:* = myRoot.unitW / 75;
                clearShell.mySubmit.scaleY = myRoot.unitW / 75;
                clearShell.mySubmit.scaleX = _loc_1;
                clearShell.mySubmit.x = 6;
                clearShell.mySubmit.y = Math.round((clearShell.submitBG.y + 1));
                clearShell.myArrow.x = Math.round(clearShell.submitBG.x + clearShell.submitBG.width - 10 * myRoot.unitW / 75);
                clearShell.myArrow.y = Math.round(clearShell.submitBG.y + 10 * myRoot.unitW / 75);
                clearShell.myMessage.y = Math.round(clearShell.submitBG.y + clearShell.submitBG.height + 13 * myRoot.unitW / 75);
                var _loc_1:* = myRoot.unitW / 75;
                clearShell.myMessage.scaleY = myRoot.unitW / 75;
                clearShell.myMessage.scaleX = _loc_1;
            }
            if (myLink != null)
            {
                var _loc_1:* = myRoot.unitW / 75;
                myLink.field1.field.scaleY = myRoot.unitW / 75;
                myLink.field1.field.scaleX = _loc_1;
                myLink.field1.inputBG.width = Math.round(6 * myRoot.unitW + 5 * myRoot.gutterW);
                myLink.field1.inputBG.height = Math.round(26 * myRoot.unitW / 75);
                var _loc_1:* = Math.round(6 * (myRoot.unitW + myRoot.gutterW));
                myLink.saveBtn.x = Math.round(6 * (myRoot.unitW + myRoot.gutterW));
                myLink.saveBG.x = _loc_1;
                var _loc_1:* = Math.round(myLink.field1.y);
                myLink.saveBtn.y = Math.round(myLink.field1.y);
                myLink.saveBG.y = _loc_1;
                var _loc_1:* = Math.round(80 * myRoot.unitW / 75);
                myLink.saveBtn.width = Math.round(80 * myRoot.unitW / 75);
                myLink.saveBG.width = _loc_1;
                var _loc_1:* = Math.round(26 * myRoot.unitW / 75);
                myLink.saveBtn.height = Math.round(26 * myRoot.unitW / 75);
                myLink.saveBG.height = _loc_1;
                myLink.mySave.x = myLink.saveBG.x + 3;
                myLink.mySave.y = myLink.saveBG.y + 1;
                var _loc_1:* = myRoot.unitW / 75;
                myLink.mySave.scaleY = myRoot.unitW / 75;
                myLink.mySave.scaleX = _loc_1;
                myLink.saveArrow.x = Math.round(myLink.saveBG.x + myLink.saveBG.width - 10 * myRoot.unitW / 75);
                myLink.saveArrow.y = Math.round(myLink.saveBG.y + 10 * myRoot.unitW / 75);
                myLink.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                myLink.y = Math.round(myRoot.headerH + 2 * myRoot.unitH + myRoot.gutterH - 8 * myRoot.unitW / 75 - myLink.height);
            }
            return;
        }

        function saveBtnClick(event:MouseEvent)
        {
            myRoot.bookmarkLightbox();
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function buildLongTitle() : void
        {
            var _loc_1:String = null;
            _loc_1 = "<span class=\'myBold\'>Bookmark Set #" + myRoot.myBookmarksID + "</span><br>Created " + myRoot.bookmarksXML.@date;
            longText = new LongText(myRoot, _loc_1);
            longText.alpha = 1;
            addChild(longText);
            doResize();
            return;
        }

        function btnRollOver(event:MouseEvent)
        {
            TweenMax.to(clearShell.submitBG, fadeSpeed, {tint:myRoot.hotColor, overwrite:true});
            return;
        }

        function btnRollOut(event:MouseEvent)
        {
            TweenMax.to(clearShell.submitBG, fadeSpeed, {tint:myRoot.coldColor, overwrite:true});
            return;
        }

        function saveBtnRollOver(event:MouseEvent)
        {
            TweenMax.to(myLink.saveBG, fadeSpeed, {tint:myRoot.hotColor, overwrite:true});
            return;
        }

        function btnClick(event:MouseEvent)
        {
            myRoot.clearBookmarks();
            clearShell.myMessage.text = "Your bookmarks have been cleared";
            setTimeout(resetField, 750);
            return;
        }

        function resetField() : void
        {
            clearShell.myMessage.text = "";
            return;
        }

        public function fadeInShell() : void
        {
            visible = true;
            return;
        }

        function focusInListener(event:FocusEvent) : void
        {
            if (stage.displayState == StageDisplayState.FULL_SCREEN)
            {
                myRoot.closeFullscreen();
            }
            return;
        }

        function saveBtnRollOut(event:MouseEvent)
        {
            TweenMax.to(myLink.saveBG, fadeSpeed, {tint:myRoot.coldColor, overwrite:true});
            return;
        }

    }
}
